package tmt.usercenter.web.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.tmt.annotation.Select2OptionItem;
import com.tmt.jpafieldvalueconvert.JpaFieldValueConvertListener;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import tmt.usercenter.web.domain.AuthResource;
import tmt.usercenter.web.domain.AuthScope;
import tmt.usercenter.web.domain.BaseCreator;
import tmt.usercenter.web.domain.ClientSystem;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 客户系统获得的授权资源。
 */
@Getter
@Setter
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
@EntityListeners({JpaFieldValueConvertListener.class, AuditingEntityListener.class})
@JsonIdentityInfo(generator = JSOGGenerator.class)
public class ClientSystemResource extends BaseCreator implements Serializable {

	@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "clientSystem_id", nullable = false)
	private ClientSystem clientSystem;

	@Select2OptionItem
	@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "authResource_id", nullable = false)
	private AuthResource authResource;

}
